#装饰器语法
#1.普通装饰器
# def outer(func):
#     def inner():
#         print('成功要到微信...')
#         func()
#         print('约会,看电影...')
#     return inner
#
# #使用装饰器语法实现
# @outer
# def love():
#     print('跟妹子畅谈人生...')
# love()

#2.装饰器嵌套
'''
def kuozhan(f):
    def kzinner():
        print('扩展1')
        f()
        print('扩展2')
    return kzinner

def outer(func):
    def inner():
        print('成功要到微信...')
        func()
        print('约会,看电影...')
    return inner

@kuozhan
@outer
def love():
    print('跟妹子畅谈人生...')
love()
'''

#3.对带有参数的函数进行装饰
'''
def outer(func):
    def inner(var):
        print('成功要到微信...')
        func(var)
        print('约会,看电影...')
    return inner

@outer
def love(name):
    print(f'跟{name}妹子畅谈人生...')
love('思思')
'''

#4.带有多参数装饰器
'''
def outer(func):
    def inner(who,name,*args,**kwargs):
        print('成功要到微信...')
        func(who,name,*args,**kwargs)
        print('约会,看电影...')
    return inner

@outer
def love(who,name,*args,**kwargs):
    print(f'{who}跟{name}妹子畅谈人生...')
    print(f'跟{name}妹子畅谈人生...')
    print('还去吃了美食',args)
    print(kwargs)
love('三多','思思','火锅','辣条','麻辣烫',mov='唐山大地震')
'''

#5.带参数的装饰器,装饰无参数的函数
'''
def kuozhan(var):
    def outer(func):
        print(var)
        def inner1():
            print('拿到妹子的微信...')
            func()
            print('看一场电影...')
        def inner2():
            print('妹子教会了我人生...')
        if var=='高富帅':
            return inner1
        else:
            return inner2
    return outer

@kuozhan('高富帅')
def love():
    print('谈谈人生和理想...')
love()
'''

#对类内部方法进行修饰
'''
def outer(func):
    def inner(var):
        print('拿到妹子的微信...')
        func(var)
        print('看一场电影...')
    return inner

class Demo():
    @outer
    def love(self):
        print('和妹子谈谈人生和理想...')

# Demo.love()
a=Demo()
a.love()
'''

#7.用类装饰器装饰原函数
'''
class Outer():
    def __call__(self,func):
        def inner():
            print('拿到妹子的微信...')
            func()
            print('看一场电影...')
        return inner
@Outer()
def love():
    print('和妹子谈谈人生和理想...')
love()
'''

#用类方法装饰函数
'''
class Outer():
    def newinner(func):
        Outer.func=func
        return Outer.inner

    def inner():
        print('拿到妹子的微信...')
        Outer.func()
        print('看一场电影...')
@Outer.newinner
def love():
    print('和妹子谈谈人生和理想...')
love()
'''

